@extends('default.layouts.adminPublic')
@section('title', '招聘会设置')
@section('headcss')
    @parent
    <link rel="stylesheet" href="{{asset('/default/css/admin/jobFair.css')}}">
    <link rel="stylesheet" type="text/css" href="{{asset('/vendor/webuploader/dist/webuploader_img.css')}}">
    @endsection
    @section('content')
            <!--导航开始-->
    <div class="crumb_warp">
        <i class="fa fa-home"></i> <a href="{{url('admin/job_fair_pic')}}">首页</a> &raquo; 招聘会设置
    </div>
    <!--导航结束-->
    <!--结果集标题与导航组件 开始-->
    <div class="con">
        <div class="conMain">
            <div class="pic">
                <div class="manage">
                    <div class="mark">
                        <p>设置普通招聘会背景图片</p>
                    </div>
                    {{--设置上传图片--}}
                    <div class="picInfo">
                        <div class="picUpload" id="pic">
                            <span class="editpic">修改图片</span>
                            <img src="{{asset($recruitmentPic)}}"/>
                        </div>
                        <div class="del"><a onclick="delPic('{{$recruitmentad->id or ''}}')">删除图片</a></div>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!--结果集标题与导航组件 结束-->
@endsection
@section('footerjs')
    @parent
    <script type="text/javascript" src="{{asset('/vendor/webuploader/dist/webuploader.min.js')}}"></script>
    <script type="text/javascript">
        $(function(){
            $('#pic').hover(function(){
                $(this).find('.editavatar').show();
            }, function(){
                $(this).find('.editavatar').hide();
            });
            uploadPic('#pic');
        });
        /**
         * 删除图片
         * param uploadPic
         */
        function delPic($id){
            layer.confirm('您确定要删除这个招聘会图片吗？', {
                btn: ['确定', '取消'] //按钮
            }, function(){
                $.post("{{url('admin/del_pic?id=')}}" + $id, {'_token': "{{csrf_token()}}"}, function(data){
                    if(data.status == 0){
                        layer.msg(data.msg, {icon: 5, time: 1500});
                    }else{
                        layer.msg(data.msg, {icon: 6, time: 1500});
                        location.href = '/admin/job_fair_pic';
                    }
                });
            });
        }
        /**
         * 上传图片
         * param uploadPic
         */
        function uploadPic(uploadPic){
            var uploaderavatar = WebUploader.create({
                auto: true,
                formData: {
                    _token: "{{csrf_token()}}"
                },
                duplicate: true,
                // swf文件路径
                swf: BASE_URL + 'vendor/webuploader/dist/Uploader.swf',
                // 文件接收服务端。
                server: "{{asset('/admin/upload_pic')}}",
                // 选择文件的按钮。可选。
                // 内部根据当前运行是创建，可能是input元素，也可能是flash.
                pick: {
                    id: uploadPic,
                    multiple: false
                },
                compress:false,
                accept: {
                    title: 'Images',
                    extensions: 'gif,jpg,jpeg,bmp,png',
                    mimeTypes: '.gif,.jpg,.jpeg,.bmp,.png*'
                },
                fileSingleSizeLimit: 2000 * 1024
                // 不压缩image, 默认如果是jpeg，文件上传前会压缩一把再上传！
//                resize: false
            });
            //上传文件出错时
            uploaderavatar.on('error', function(file){
                if(file == 'F_EXCEED_SIZE'){
                    layer.msg('文件大小不能超过2M！',{time:1200});
                }
                if(file == 'F_DUPLICATE'){
                    layer.msg('此文件已经存在队列当中，不能重复上传！',{time:1200});
                }
                if(file == 'Q_EXCEED_NUM_LIMIT'){
                    layer.msg('你已经上传了文件！',{time:1200});
                }
                if(file == 'Q_TYPE_DENIED'){
                    layer.msg('文件类型不匹配，请重新上传！',{time:1200});
                }
            });
            uploaderavatar.on('uploadSuccess', function(file, response){
                if(response.status == 200){
                    $(uploadPic).find('img').attr("src", response.url);
                }else if(response.error == 404){
                    layer.msg(response.info,{time:1200});
                }else{
                    layer.msg(response.info,{time:1200});
                }
            });
        }
    </script>
@endsection
